﻿<%@ Page Language="C#" Trace="false" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="import.aspx.cs" Inherits="ImportPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
		<script>
		function validateImportXmlForm()
		{
			valDisplayer.hideAllValidationErrors();
			var noErrors = true;

			var fileSelElem = $("#<% =  ExcelXmlFileSel.ClientID %>");
			var fileElem = $("#<% = ExcelXmlFile.ClientID %>");

			if (!fileSelElem.val())
			{
				if (!fileElem.val())
				{
					valDisplayer.showValidationError("Please either select an existing file from the list or select a file to upload.", fileElem);
					noErrors = false;
				}
			}

			return noErrors;
		}
		function validateImportExcelForm()
		{
			valDisplayer.hideAllValidationErrors();
			var noErrors = true;

			var fileSelElem = $("#<% =  ExcelFileSel.ClientID %>");
			var fileElem = $("#<% = ExcelFile.ClientID %>");

			if (!fileSelElem.val())
			{
				if (!fileElem.val())
				{
					valDisplayer.showValidationError("Please either select an existing file from the list or select a file to upload.", fileElem);
					noErrors = false;
				}
			}

			return noErrors;		
		}
		</script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="body" Runat="Server">

	<form id="form1" runat="server">

		<h1>Import texts</h1>
		<p>
			Excel sheets which have been exported from the system (or which uses the same format) can be imported here. If you import an Excel file it will always be the first sheet that is imported.
		</p>
		<p>
			<i>Note about the two different import options:</i> The &quot;Excel XML&quot; option requires you to save the file in a certain way from Excel. The &quot;Excel or Text&quot; option will accept any Excel or text format, but requires you to install the <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c06b8369-60dd-4b64-a44b-84b371ede16d&displaylang=en" target="DownloadAccessDriverWin">Microsoft Access Database Engine 2010 Redistributable</a> on your server.<br />
			If you are using OpenOffice the Excel-XML option corresponds to the "Microsoft Excel XML 2003" option in the "Save As" dialog.
		</p>
		
		<asp:PlaceHolder runat="server" ID="Step1Plh">
			<h2>Step 1 - upload file</h2>
			<p>
				Start by uploading the file you wish to import or select an existing file. You will be presented with a list of all the changes that the import file will apply . You can then choose to either commit the changes or abort the import.
			</p>
			
			

			<div class="clearfix">
				<div class="left exportBox" style="width: 40%; margin-right: 20px;">
					<h2 style="margin-top: 0px;">Import Excel-XML</h2>
					<p>
						The format is the <a href="http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats" target="_blank">Microsoft Office XML format</a> which can be opened by any version of Excel from the year 2000 and beyond.<br />
						<br />
						<br />
					</p>

					<div style="margin-top: 10px;">
						<label>Existing file</label><br />
						<select id="ExcelXmlFileSel" style="width: 220px;" name="ExcelXmlFileSel" onchange="if ($(this).val() == '') { $('#excelXmlUpload').css('visibility', 'visible'); } else { $('#excelXmlUpload').css('visibility', 'hidden'); }" runat="server"></select>
						<div id="excelXmlUpload" style="margin-top: 5px;">
							<label>File:</label><br />
							<input type="file" id="ExcelXmlFile" runat="server" />
						</div>
					</div>
					<div style="text-align: center; margin-top: 15px; margin-bottom: 10px;">
						<button type="button" class="mainSubmit" onclick="if ( ! validateImportXmlForm()) { return false;	}" onserverclick="SelectExcelXmlBtnClicked" runat="server">Upload / Select</button>
					</div>
				</div>

				<div class="left exportBox" style="width: 40%;">
					<h2 style="margin-top: 0px;">Import Excel or Text format</h2>
					<p>
						Imports .xls or .xlsx, .csv or .txt formats. This option requires that you have installed the <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c06b8369-60dd-4b64-a44b-84b371ede16d&displaylang=en" target="DownloadAccessDriverWin">Microsoft Access Database Engine 2010 Redistributable</a>.<br />
						<br />
						<br />
					</p>
					<div style="margin-top: 10px;">
						<label>Existing file</label><br />
						<select id="ExcelFileSel" style="width: 220px;" name="ExcelFileSel" onchange="if ($(this).val() == '') { $('#excelUpload').css('visibility', 'visible'); } else { $('#excelUpload').css('visibility', 'hidden'); }" runat="server"></select>
						<div id="excelUpload" style="margin-top: 5px;">
							<label>File:</label><br />
							<input type="file" id="ExcelFile" runat="server" />
						</div>
					</div>
					<div style="text-align: center; margin-top: 15px; margin-bottom: 10px;">
						<button type="button" class="mainSubmit" onclick="if ( ! validateImportExcelForm()) { return false;	}" onserverclick="SelectExcelBtnClicked" runat="server">Upload / Select</button>
					</div>
				</div>

			</div>
		</asp:PlaceHolder>
		<asp:PlaceHolder runat="server" visible="false" ID="Step2Plh">
			<h2>Step 2 - review changes and commit</h2>
			<p>
				Below is a summary of the changes the selected file will apply to your project file.<br />
				- means the text already exists in that language and will be updated.<br />
				+ means it does not exist in that language and will be created by the import.<br />
			</p>
			<p>
				Click the "Import texts" button to finalize the import and write the data to the project file. Once imported you will not be able to undo the changes, so always back up your project file first.
			</p>
			
			<div style="max-height: 600px; overflow: auto;">
				<asp:Literal ID="ResultLit" runat="server" />
			</div>
			
			<input type="hidden" id="FileNameAndPathToImport" runat="server" />
			
			<asp:PlaceHolder id="ImportExcelXmlPlh" runat="server">
				<a href="default.aspx">abort import</a>&nbsp;&nbsp;&nbsp;&nbsp;<button id="ImportExcelXmlBtn" type="button" class="mainSubmit" onserverclick="ImportExcelXmlBtnClicked" runat="server">Commit to project file</button>
			</asp:PlaceHolder>
			<asp:PlaceHolder id="ImportExcelPlh" runat="server">
				<a href="default.aspx">abort import</a>&nbsp;&nbsp;&nbsp;&nbsp;<button id="ImportXmlBtn" type="button" class="mainSubmit" onserverclick="ImportXmlBtnClicked" runat="server">Commit to project file</button>
			</asp:PlaceHolder>

		</asp:PlaceHolder>
		<asp:PlaceHolder runat="server" visible="false" ID="ResultPlh">
			<h2>Import successful</h2>
			<p>
				The import completed successfully. The following modifications where made:
			</p>

			<div style="max-height: 600px; overflow: auto;">
				<asp:Literal ID="ResultFinalPlh" runat="server" />
			</div>

		</asp:PlaceHolder>

	</form>
	
	<br />

</asp:Content>